package cn.saddyfire.pattern.prototype.deep_clone;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

/**
 * @author Dee
 * @date 2024/1/23
 * <p>Description:
 */
public class CitationTest {
    public static void main(String[] args) throws Exception {
        Citation citation = new Citation();
        Student stu = new Student();
        stu.setName("张三");
        citation.setStu(stu);
        //输出至文件
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("./a.txt"));
        oos.writeObject(citation);
        oos.close();
        //读取输入流
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("./a.txt"));
        //读取对象
        Citation citation1 = (Citation) ois.readObject();
        ois.close();
        //重新赋值
        citation1.getStu().setName("李四");
        citation.show();
        citation1.show();
    }
}
